import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

/**
 * @author Lei
 * @create 2022-05-22 17:42
 */
public class ViewMoreBook extends View<ControllerMoreBook> {
    private JTextField t1;
    private JTextField t2;

    public ViewMoreBook(Library m, ControllerMoreBook c) {
        super(m, c);
        t1 = new JTextField("Type a user name here");
        add(t1);
        t2 = new JTextField("Type a number of books here");
        add(t2);
        setLayout(new GridLayout(3,1));
        Button tell_me_the_book_number = new Button("More Book");
        tell_me_the_book_number.addActionListener(new MyActionListener(this));
        add(tell_me_the_book_number);
    }

    @Override
    public void update() {

    }

    class MyActionListener implements ActionListener {


        private JFrame parent;

        public MyActionListener(JFrame parent) {
            this.parent = parent;
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            String name = t1.getText();
            String number = t2.getText();
            String res = c.moreBook(name, number);
            JOptionPane.showMessageDialog(parent, res);
        }
    }
}
